package com.aptech.oas.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

import com.aptech.oas.model.User;
import com.aptech.oas.util.SessionFactoryUtil;

public class UserDaoImpl implements UserDao {

	@Override
	public User selectUserByWorkNo(String workNo) {
		Configuration cfg=new Configuration();
		SessionFactory sessionFactory=cfg.configure().buildSessionFactory();
		Session session=sessionFactory.openSession();
		User user=session.get(User.class, workNo);
		session.close();
		sessionFactory.close();
		return user;
	}

	public List<User> selectAllUser() {
		SessionFactory sessionFactory=SessionFactoryUtil.get();
		Session session=sessionFactory.openSession();
		Query q=session.createQuery("from User");
		List<User> users=q.list();
		return users;
	}

}
